import os

import weaviate
import yaml

class Database:
    def __init__(self, port: int, data_path: str):
        self.client = weaviate.connect_to_embedded(port=port, persistence_data_path=data_path)

    def get_client(self):
        return self.client

# 获取当前脚本所在目录的路径
current_dir = os.path.dirname(os.path.abspath(__file__))

# 项目根目录路径
project_root = os.path.dirname(current_dir)

# 读取配置信息
config_path = os.path.join(project_root, "config.yaml")
with open(config_path, 'r') as file:
    config = yaml.load(file, Loader=yaml.FullLoader)

# 构建数据路径，确保是项目根目录下的weaviate_data目录
data_path = os.path.join(project_root, "weaviate_data")

# 创建一个数据库实例
db = Database(port=config["weaviate"]["port"], data_path=data_path)
